﻿using EnvDTE;
using System.Linq;
using EnvDTE80;

namespace wscf_lightblue_VSAddIn
{
	/// <summary>
	/// Writes message to a 'wscf.lightblue' pane in the Output window.
	/// </summary>
	public class OutputWindowWriter
	{
		private readonly OutputWindowPane outputWindowPane;

		/// <summary>
		/// Initializes a new instance of the <see cref="OutputWindowWriter"/> class.
		/// </summary>
		/// <param name="dte">The application object.</param>
		public OutputWindowWriter(DTE2 dte)
		{
			OutputWindow outputWindow = dte.ToolWindows.OutputWindow;

			outputWindowPane = outputWindow.OutputWindowPanes
				.OfType<OutputWindowPane>()
				.Where(p => p.Name == "wscf.lightblue")
				.FirstOrDefault() ?? outputWindow.OutputWindowPanes.Add("wscf.lightblue");

			outputWindowPane.Clear();
		}

		/// <summary>
		/// Clears the wscf.lightblue pane in the Output window.
		/// </summary>
		public void Clear()
		{
			outputWindowPane.Clear();
		}

		/// <summary>
		/// Writes a message to the 'wscf.lightblue' pane.
		/// </summary>
		/// <param name="message">The message.</param>
		public void WriteMessage(string message)
		{
			outputWindowPane.Activate();
			outputWindowPane.OutputString("\r\n" + message);
		}
	}
}